package cn.com.test.common;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.ModelAndView;

@Aspect
@Controller
@RequestMapping("/test")
public class CommonController {

	@Autowired
	private CommonService commonServiceImpl;

	@Autowired
	private TestService testService;

	@RequestMapping("")
	@ResponseBody
	public String test(){
		//commonServiceImpl.doOption();
		testService.test1();
		Object o = SpringContextUtil.getApplicationContext().getBean("simpleAspect");
		System.out.println(o);
		return "test";
	}

/*	@Before(value = "execution(* cn.com.test.common.CommonService.doOption(..))")
	public void aspect(JoinPoint joinPoint) {
		System.out.println("进入切面--");
	}*/

	@RequestMapping("/usebean")
	public String toUserBean(ModelMap map) {
		System.out.println("toUseBean");
		map.put("name", "陈伟标");
		return "jspTest/usebean";
	}

	@RequestMapping("/action")
	public String toUserBean() {
		System.out.println("action");
		return "jspTest/action";
	}

	@RequestMapping("/usebean1")
	public ModelAndView toUserBean(ModelAndView modelAndView) {
		System.out.println("toUseBean1");
		modelAndView.setViewName("jspTest/usebean");
		modelAndView.addObject("name", "ModelAndViewName");
		return modelAndView;
	}

	/**
	 * @Description: 跳转至文件上传页面
	 * @author chenwb
	 * @date 2019/12/17 20:52
	 * @param
	 * @return 输出参数
	 */
	@RequestMapping("/upload")
	public String toUpoad() {
		System.out.println("upload");
		return "jspTest/upload";
	}

/*	@RequestMapping("/{pageName}")
	public String toQueryUser(@PathVariable("pageName") String pageName) {
		System.out.println("pageName " + pageName);
		return "jspTest/" + pageName;
	}*/

}